package mastermind.img;

import mastermind.gui.controls.RatePinUI.RATE_STATE;

import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Display;

public class ImageLoader
{

	private static Image[]		_pins							= null;
	private static Image		_hole;
	private static Image		_line;
	private static Image		_solution;
	private static Image		_rate_right;
	private static Image		_rate_wrong;
	private static Image		_rate_none;
	private static Image		_selected;
	private static Image		_appBig;
	private static Image		_appSmall;

	public static final Color	COLOR_BACKGROUND_GREEN			= new Color(Display.getDefault(), new RGB(47, 141, 89));
	public static final Color	COLOR_BACKGROUND_BROWN			= new Color(Display.getDefault(), new RGB(220, 150, 110));
	public static final Color	COLOR_BACKGROUND_BROWN_HOVER	= new Color(Display.getDefault(), new RGB(230, 170, 130));

	private static void init()
	{
		if (_pins == null)
		{
			_pins = new Image[10];
			for (int i = 0; i < 10; i++)
			{
				_pins[i] = new Image(Display.getDefault(), ImageLoader.class.getResourceAsStream("/mastermind/img/pins/" + i + ".png"));
			}

			_solution = new Image(Display.getDefault(), ImageLoader.class.getResourceAsStream("/mastermind/img/solution.png"));
			_hole = new Image(Display.getDefault(), ImageLoader.class.getResourceAsStream("/mastermind/img/hole.png"));
			_rate_right = new Image(Display.getDefault(), ImageLoader.class.getResourceAsStream("/mastermind/img/pins/right.png"));
			_rate_wrong = new Image(Display.getDefault(), ImageLoader.class.getResourceAsStream("/mastermind/img/pins/wrong.png"));
			_rate_none = new Image(Display.getDefault(), ImageLoader.class.getResourceAsStream("/mastermind/img/pins/none.png"));
			_selected = new Image(Display.getDefault(), ImageLoader.class.getResourceAsStream("/mastermind/img/pins/selected.png"));
			_appBig = new Image(Display.getDefault(), ImageLoader.class.getResourceAsStream("/mastermind/img/app48.ico"));
			_appSmall = new Image(Display.getDefault(), ImageLoader.class.getResourceAsStream("/mastermind/img/app16.ico"));
		}
	}

	public static Image getSolution()
	{
		init();
		return _solution;
	}

	public static Image getLine()
	{
		init();
		return _line;
	}

	public static Image getPin(byte color)
	{
		init();
		if (color == -1)
			return _hole;
		if (_pins.length < color + 1)
			return null;
		return _pins[color];
	}

	public static Image getRate(RATE_STATE state)
	{
		switch (state)
		{
		case RIGHT:
			return _rate_right;

		case WRONG:
			return _rate_wrong;

		case NONE:
			return _rate_none;
		}
		return null;
	}

	public static Image getSelected()
	{
		init();
		return _selected;
	}

	public static Image getAppBig()
	{
		init();
		return _appBig;
	}

	public static Image getAppSmall()
	{
		init();
		return _appSmall;
	}

}
